/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "movement_service_test.h"

#include <iostream>
#include <chrono>
#include <thread>
#include <gtest/gtest.h>
#include <if_system_ability_manager.h>
#include <ipc_skeleton.h>
#include <string_ex.h>

#include "movement_common.h"
#include "movement_client.h"

using namespace testing::ext;
using namespace OHOS::Msdp;
using namespace OHOS;
using namespace std;

void MovementServiceTest::MovementTestCallback::OnMovementChanged(const MovementDataUtils::MovementData& movementData)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Enter");
    GTEST_LOG_(INFO) << "MovementTestCallback type: " << movementData.type;
    GTEST_LOG_(INFO) << "MovementTestCallback value: " << movementData.value;
    EXPECT_EQ(true, movementData.type == MovementDataUtils::MovementType::TYPE_IN_VEHICLE &&
        movementData.value == MovementDataUtils::MovementValue::VALUE_ENTER) << "MovementTestCallback falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest001
 * @tc.desc: Test movement callback in proxy
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest001, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest001 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_IN_VEHICLE;
    auto& movementClient = MovementClient::GetInstance();
    sptr<ImovementCallback> cb = new MovementTestCallback();
    GTEST_LOG_(INFO) << "Start register";
    movementClient.SubscribeCallback(type, cb);
    GTEST_LOG_(INFO) << "Cancel register";
    movementClient.UnSubscribeCallback(type, cb);
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest002
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_IN_VEHICLE
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest002, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest002 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_IN_VEHICLE;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_IN_VEHICLE &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest003
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_IN_AUTO
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest003, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest003 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_IN_AUTO;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_IN_AUTO &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest004
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_IN_PLANE
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest004, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest004 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_IN_PLANE;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_IN_PLANE &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest005
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_IN_METRO
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest005, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest005 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_IN_METRO;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_IN_METRO &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest006
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_IN_ELEVATOR
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest006, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest006 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_IN_ELEVATOR;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_IN_ELEVATOR &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest007
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_ON_BICYCLE
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest007, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest007 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_ON_BICYCLE;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_ON_BICYCLE &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest008
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_STAY
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest008, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest008 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_STAY;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_STAY &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest009
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_STILL
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest009, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest009 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_STILL;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_STILL &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest010
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_RELATIVE_STILL
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest010, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest010 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_RELATIVE_STILL;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_RELATIVE_STILL &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest011
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_ON_FOOT
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest011, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest011 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_ON_FOOT;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_ON_FOOT &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest012
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_WALKING
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest012, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest012 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_WALKING;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_WALKING &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest013
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_WALKING_HANDHOLD
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest013, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest013 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_WALKING_HANDHOLD;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_WALKING_HANDHOLD &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest014
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_FAST_WALKING
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest014, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest014 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_FAST_WALKING;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_FAST_WALKING &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest015
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_RUNNING
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest015, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest015 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_RUNNING;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_RUNNING &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest016
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_LYING_POSTURE
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest016, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest016 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_LYING_POSTURE;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_LYING_POSTURE &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest017
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_SMART_FLIGHT
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest017, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest017 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_SMART_FLIGHT;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_SMART_FLIGHT &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}

/**
 * @tc.name: MovementServiceTest018
 * @tc.desc: Test get movement data in proxy, MovementType is TYPE_HIGH_SPEED_RAIL
 * @tc.type: FUNC
 */
HWTEST_F (MovementServiceTest, MovementServiceTest018, TestSize.Level0)
{
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "MovementServiceTest018 Enter");
    MovementDataUtils::MovementType type = MovementDataUtils::MovementType::TYPE_HIGH_SPEED_RAIL;
    auto& movementClient = MovementClient::GetInstance();
    MovementDataUtils::MovementData data = movementClient.GetMovementData(type);
    GTEST_LOG_(INFO) << "type: " << data.type;
    GTEST_LOG_(INFO) << "value: " << data.value;
    EXPECT_EQ(true, data.type == MovementDataUtils::MovementType::TYPE_HIGH_SPEED_RAIL &&
        data.value == MovementDataUtils::MovementValue::VALUE_INVALID) << "GetMovementData falied";
    MOVEMENT_HILOGI(MOVEMENT_MODULE_SERVICE, "Exit");
}
